<!DOCTYPE html>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">

    <!--[if lt IE 9]>
        <style>body {display: none; background: none !important} </style>
        <meta http-equiv="Refresh" Content="0; url=//outdatedbrowser.com/" />
    <![endif]-->

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="author" content="Ren ZM">



<meta name="description" content="学习基础OpenGL，设计一个简单的渲染框架。">
<meta name="keywords" content="note">
<meta property="og:type" content="article">
<meta property="og:title" content="simple opengl">
<meta property="og:url" content="https://littlepro.gitee.io/mytpages/2019/11/18/simple-opengl/index.html">
<meta property="og:site_name" content="Xbiubiubiu">
<meta property="og:description" content="学习基础OpenGL，设计一个简单的渲染框架。">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-11-23T05:17:53.038Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="simple opengl">
<meta name="twitter:description" content="学习基础OpenGL，设计一个简单的渲染框架。">

<link rel="apple-touch-icon" href="/mytpages//apple-touch-icon.png">


    <link rel="alternate" href="/atom.xml" title="Xbiubiubiu" type="application/atom+xml">



    <link rel="shortcut icon" href="/mytpages//favicon.png">



    <link href="//cdn.bootcss.com/animate.css/3.5.1/animate.min.css" rel="stylesheet">



    <link href="//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.css" rel="stylesheet">



    <script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script>
    <link href="//cdn.bootcss.com/pace/1.0.2/themes/blue/pace-theme-minimal.css" rel="stylesheet">


<link rel="stylesheet" href="/mytpages/css/style.css">



<link href="//cdn.bootcss.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet">


<title>simple opengl | Xbiubiubiu</title>

<script src="//cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<script src="//cdn.bootcss.com/clipboard.js/1.5.10/clipboard.min.js"></script>

<script>
    var yiliaConfig = {
        fancybox: true,
        animate: true,
        isHome: false,
        isPost: true,
        isArchive: false,
        isTag: false,
        isCategory: false,
        fancybox_js: "//cdn.bootcss.com/fancybox/2.1.5/jquery.fancybox.min.js",
        scrollreveal: "//cdn.bootcss.com/scrollReveal.js/3.1.4/scrollreveal.min.js",
        search: false
    }
</script>


    <script> yiliaConfig.jquery_ui = [false]; </script>



    <script> yiliaConfig.rootUrl = /mytpages/; </script>







    <script src="/mytpages/live2d-widget/autoload.js"></script>


</head></html>
<body>
  <div id="container">
    <div class="left-col">
    <div class="overlay"></div>
<div class="intrude-less">
    <header id="header" class="inner">
        <a href="/mytpages/" class="profilepic">
            <img src="/mytpages//img/avatar.png" class="animated zoomIn">
        </a>
        <hgroup>
          <h1 class="header-author"><a href="/mytpages/">Ren ZM</a></h1>
        </hgroup>

        
        <p class="header-subtitle">--ロリは正義</p>
        

        


        
            <div id="switch-btn" class="switch-btn">
                <div class="icon">
                    <div class="icon-ctn">
                        <div class="icon-wrap icon-house" data-idx="0">
                            <div class="birdhouse"></div>
                            <div class="birdhouse_holes"></div>
                        </div>
                        <div class="icon-wrap icon-ribbon hide" data-idx="1">
                            <div class="ribbon"></div>
                        </div>
                        
                        <div class="icon-wrap icon-link hide" data-idx="2">
                            <div class="loopback_l"></div>
                            <div class="loopback_r"></div>
                        </div>
                        
                        
                        <div class="icon-wrap icon-me hide" data-idx="3">
                            <div class="user"></div>
                            <div class="shoulder"></div>
                        </div>
                        
                    </div>
                    
                </div>
                <div class="tips-box hide">
                    <div class="tips-arrow"></div>
                    <ul class="tips-inner">
                        <li>菜单</li>
                        <li>标签</li>
                        
                        <li>友情链接</li>
                        
                        
                        <li>关于我</li>
                        
                    </ul>
                </div>
            </div>
        

        <div id="switch-area" class="switch-area">
            <div class="switch-wrap">
                <section class="switch-part switch-part1">
                    <nav class="header-menu">
                        <ul>
                        
                            <li><a href="/mytpages//mytpages/../">主页</a></li>
                        
                            <li><a href="/mytpages//mytpages/../archives/">所有文章</a></li>
                        
                            <li><a href="/mytpages//mytpages/../tags/">标签云</a></li>
                        
                            <li><a href="/mytpages//mytpages/../about/">关于我</a></li>
                        
                        </ul>
                    </nav>
                    <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" href="mailto:784709355@qq.com" title="Email"></a>
                            
                                <a class="fa GitHub" href="https://github.com/rzzz" title="GitHub"></a>
                            
                                <a class="fa Gitee" href="https://gitee.com/littlepro" title="Gitee"></a>
                            
                                <a class="fa V2EX" href="/mytpages/" title="V2EX"></a>
                            
                                <a class="fa 知乎" href="/mytpages/" title="知乎"></a>
                            
                                <a class="fa 网易云音乐" href="/mytpages/" title="网易云音乐"></a>
                            
                                <a class="fa bilibili" href="/mytpages/" title="bilibili"></a>
                            
                        </ul>
                    </nav>
                </section>
                
                
                <section class="switch-part switch-part2">
                    <div class="widget tagcloud" id="js-tagcloud">
                        <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/JavaScript/">JavaScript</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/MySql/">MySql</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/NodeJS/">NodeJS</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/Nodejs/">Nodejs</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/PS3/">PS3</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/c/">c</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/c/">c++</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/cocos2dx/">cocos2dx</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/markdown/">markdown</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/note/">note</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/sort/">sort</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/test/">test</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/tool/">tool</a></li><li class="tag-list-item"><a class="tag-list-link" href="/mytpages/tags/usage/">usage</a></li></ul>
                    </div>
                </section>
                
                
                
                <section class="switch-part switch-part3">
                    <div id="js-friends">
                    
                      <a class="main-nav-link switch-friends-link" href="https://hexo.io">Hexo</a>
                    
                      <a class="main-nav-link switch-friends-link" href="https://pages.github.com/">GitHub</a>
                    
                      <a class="main-nav-link switch-friends-link" href="http://moxfive.xyz/">MOxFIVE</a>
                    
                    </div>
                </section>
                

                
                
                <section class="switch-part switch-part4">
                
                    <div id="js-aboutme">ロリは正義</div>
                </section>
                
            </div>
        </div>
    </header>                
</div>
    </div>
    <div class="mid-col">
      <nav id="mobile-nav">
      <div class="overlay">
          <div class="slider-trigger"></div>
          <h1 class="header-author js-mobile-header hide"><a href="/" title="回到主页">Ren ZM</a></h1>
      </div>
    <div class="intrude-less">
        <header id="header" class="inner">
            <a href="/mytpages/" class="profilepic">
                <img src="/mytpages//img/avatar.png" class="animated zoomIn">
            </a>
            <hgroup>
              <h1 class="header-author"><a href="/mytpages/" title="回到主页">Ren ZM</a></h1>
            </hgroup>
            
            <p class="header-subtitle">--ロリは正義</p>
            
            <nav class="header-menu">
                <ul>
                
                    <li><a href="/mytpages/../">主页</a></li>
                
                    <li><a href="/mytpages/../archives/">所有文章</a></li>
                
                    <li><a href="/mytpages/../tags/">标签云</a></li>
                
                    <li><a href="/mytpages/../about/">关于我</a></li>
                
                <div class="clearfix"></div>
                </ul>
            </nav>
            <nav class="header-nav">
                        <ul class="social">
                            
                                <a class="fa Email" target="_blank" href="mailto:784709355@qq.com" title="Email"></a>
                            
                                <a class="fa GitHub" target="_blank" href="https://github.com/rzzz" title="GitHub"></a>
                            
                                <a class="fa Gitee" target="_blank" href="https://gitee.com/littlepro" title="Gitee"></a>
                            
                                <a class="fa V2EX" target="_blank" href="/mytpages/" title="V2EX"></a>
                            
                                <a class="fa 知乎" target="_blank" href="/mytpages/" title="知乎"></a>
                            
                                <a class="fa 网易云音乐" target="_blank" href="/mytpages/" title="网易云音乐"></a>
                            
                                <a class="fa bilibili" target="_blank" href="/mytpages/" title="bilibili"></a>
                            
                        </ul>
            </nav>
        </header>                
    </div>
    <link class="menu-list" tags="标签" friends="友情链接" about="关于我"/>
</nav>
      <div class="body-wrap"><article id="post-simple-opengl" class="article article-type-post" itemscope itemprop="blogPost">
  
    <div class="article-meta">
      <a href="/mytpages/2019/11/18/simple-opengl/" class="article-date">
      <time datetime="2019-11-18T03:21:43.000Z" itemprop="datePublished">2019-11-18</time>
</a>


    </div>
  
  <div class="article-inner">
    
      <input type="hidden" class="isFancy" />
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      simple opengl
    </h1>
  

      </header>
      
      <div class="article-info article-info-post">
        

        
    <div class="article-tag tagcloud">
        <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/mytpages/tags/note/">note</a></li></ul>
    </div>

        <div class="clearfix"></div>
      </div>
      
    
    <div class="article-entry" itemprop="articleBody">
      
          
        <p>学习基础OpenGL，设计一个简单的渲染框架。</p>
<a id="more"></a>

<p>Application</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Application</span></span></span><br><span class="line"><span class="class">    <span class="title">LARGE_INTEGER</span> <span class="title">m_nAnimationInterval</span>;</span></span><br><span class="line">    <span class="comment">// method ----------------------------</span></span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">bool</span> <span class="title">onApplicationCreate</span><span class="params">()</span></span>&#123; <span class="keyword">return</span> <span class="literal">true</span>; &#125;;</span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">bool</span> <span class="title">onApplicationCreateFinish</span><span class="params">()</span></span>&#123; <span class="keyword">return</span> <span class="literal">true</span>; &#125;;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">setAnimationInterval</span><span class="params">(<span class="keyword">double</span> interval)</span></span>;</span><br><span class="line">        LARGE_INTEGER nFreq;</span><br><span class="line">        QueryPerformanceFrequency(&amp;nFreq);</span><br><span class="line">        m_nAnimationInterval.QuadPart = (LONGLONG)(interval * nFreq.QuadPart);</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">run</span><span class="params">()</span></span>;</span><br><span class="line">        setAnimationInterval(<span class="number">1.0</span> / <span class="number">60</span>);</span><br><span class="line">        <span class="keyword">if</span> (!onApplicationCreate())</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        <span class="keyword">if</span> (!Director::getInstance()-&gt;isInitReady())</span><br><span class="line">            <span class="keyword">return</span>;</span><br><span class="line">        onApplicationCreateFinish();</span><br><span class="line"><span class="meta">#<span class="meta-keyword">ifdef</span> DIRECTOR_LOOP</span></span><br><span class="line">        Director::getInstance()-&gt;drawScene();</span><br><span class="line">        Director::destoryInstance();</span><br><span class="line"><span class="meta">#<span class="meta-keyword">else</span></span></span><br><span class="line">        LARGE_INTEGER nFreq;</span><br><span class="line">        LARGE_INTEGER nLast;</span><br><span class="line">        LARGE_INTEGER nNow;</span><br><span class="line">        QueryPerformanceFrequency(&amp;nFreq);</span><br><span class="line">        QueryPerformanceCounter(&amp;nLast);</span><br><span class="line">        <span class="keyword">while</span> (<span class="number">1</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            QueryPerformanceCounter(&amp;nNow);</span><br><span class="line">            <span class="keyword">if</span> (nNow.QuadPart - nLast.QuadPart &gt; m_nAnimationInterval.QuadPart)</span><br><span class="line">            &#123;</span><br><span class="line">                <span class="keyword">bool</span> isOK = Director::getInstance()-&gt;drawScene((<span class="keyword">double</span>)(nNow.QuadPart - nLast.QuadPart)/(<span class="keyword">double</span>)nFreq.QuadPart);</span><br><span class="line">                nLast.QuadPart = nNow.QuadPart;</span><br><span class="line">                <span class="keyword">if</span> (!isOK)</span><br><span class="line">                &#123;</span><br><span class="line">                    Director::destoryInstance();</span><br><span class="line">                    <span class="keyword">return</span>;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">            <span class="keyword">else</span></span><br><span class="line">            &#123;</span><br><span class="line">                Sleep(<span class="number">0</span>);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">endif</span></span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">App</span> :</span> <span class="keyword">public</span> opengl_framework::Application</span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">bool</span> <span class="title">onApplicationCreate</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="keyword">auto</span> director = Director::getInstance();</span><br><span class="line">        director-&gt;setViewFactor(<span class="number">0.8</span>, <span class="number">0.8</span>);</span><br><span class="line">        director-&gt;initOpenGLWindow(<span class="number">1200</span>, <span class="number">800</span>, <span class="string">"test"</span>);</span><br><span class="line">        <span class="keyword">auto</span> img = ImageNode::create();</span><br><span class="line">        img-&gt;setZOrder(<span class="number">7</span>);</span><br><span class="line">        director-&gt;addNode(img);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br></pre></td></tr></table></figure>

<p>Director</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;GL/glew.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">&lt;GLFW/glfw3.h&gt;</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string">"node\OpenglNode.h"</span></span></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">Director</span></span></span><br><span class="line"><span class="class">    <span class="title">int</span> <span class="title">winWidth</span>;</span></span><br><span class="line">    <span class="keyword">int</span> winHeight;</span><br><span class="line">    <span class="keyword">float</span> viewWidthFactor;</span><br><span class="line">    <span class="keyword">float</span> viewHeightFactor;</span><br><span class="line">    GLFWwindow* window;</span><br><span class="line">    <span class="built_in">std</span>::<span class="built_in">vector</span>&lt;OpenglNode*&gt; nodes;</span><br><span class="line">    CameraView* camera;</span><br><span class="line">    <span class="comment">// method ------------------------</span></span><br><span class="line">    <span class="function"><span class="keyword">bool</span> <span class="title">initOpenGLWindow</span><span class="params">(<span class="keyword">int</span> width, <span class="keyword">int</span> height, <span class="keyword">const</span> <span class="keyword">char</span> * title)</span></span></span><br><span class="line"><span class="function">        winWidth </span>= width;</span><br><span class="line">        winHeight = height;</span><br><span class="line">        <span class="comment">//init opengl</span></span><br><span class="line">        <span class="built_in">cout</span> &lt;&lt; <span class="string">"Starting GLFW context, OpenGL 3.3"</span> &lt;&lt; <span class="built_in">std</span>::<span class="built_in">endl</span>;</span><br><span class="line">        <span class="comment">// Init GLFW</span></span><br><span class="line">        glfwInit();</span><br><span class="line">        <span class="comment">// Set all the required options for GLFW</span></span><br><span class="line">        glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, <span class="number">3</span>);</span><br><span class="line">        glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, <span class="number">3</span>);</span><br><span class="line">        <span class="comment">//glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_COMPAT_PROFILE);    //we use VAO,so GLFW_OPENGL_CORE_PROFILE</span></span><br><span class="line">        glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);</span><br><span class="line">        glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);</span><br><span class="line">        <span class="comment">// Create a GLFWwindow object that we can use for GLFW's functions</span></span><br><span class="line">        window = glfwCreateWindow(winWidth + <span class="number">2</span>, winHeight + <span class="number">2</span>, winTitle.c_str(), <span class="literal">nullptr</span>, <span class="literal">nullptr</span>);</span><br><span class="line">        glfwMakeContextCurrent(window);</span><br><span class="line">        glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);</span><br><span class="line">        <span class="comment">// Set the required callback functions</span></span><br><span class="line">        glfwSetKeyCallback(window, key_callback);</span><br><span class="line">        glfwSetCursorPosCallback(window, mouse_callback);</span><br><span class="line">        glfwSetScrollCallback(window, scroll_callback);</span><br><span class="line">        <span class="comment">// Set this to true so GLEW knows to use a modern approach to retrieving function pointers and extensions</span></span><br><span class="line">        glewExperimental = GL_TRUE;    <span class="comment">//we use VAO,so set this</span></span><br><span class="line">        <span class="comment">// Initialize GLEW to setup the OpenGL Function pointers</span></span><br><span class="line">        glewInit();</span><br><span class="line">        <span class="comment">// Define the viewport dimensions</span></span><br><span class="line">        <span class="comment">//int fm_width, fm_height;</span></span><br><span class="line">        <span class="comment">//glfwGetFramebufferSize(window, &amp;fm_width, &amp;fm_height);</span></span><br><span class="line">        glViewport(<span class="number">1</span>, <span class="number">1</span>, viewWidthFactor * winWidth, viewHeightFactor * winHeight);</span><br><span class="line">        glEnable(GL_DEPTH_TEST);</span><br><span class="line">        <span class="comment">// 注意这里新建了一个摄像机</span></span><br><span class="line">        camera = <span class="keyword">new</span> CameraView(glm::vec3(<span class="number">0.0f</span>, <span class="number">0.0f</span>, <span class="number">3.0f</span>));</span><br><span class="line">        isInit = <span class="literal">true</span>;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="function"><span class="keyword">bool</span> <span class="title">drawScene</span><span class="params">(<span class="keyword">float</span> dt)</span></span>;</span><br><span class="line">        thisTimeDt = dt;</span><br><span class="line">        <span class="comment">// Game loop</span></span><br><span class="line">        <span class="keyword">if</span> (glfwWindowShouldClose(window))</span><br><span class="line">        &#123;</span><br><span class="line">            <span class="comment">// Terminate GLFW, clearing any resources allocated by GLFW.</span></span><br><span class="line">            glfwTerminate();</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        realDrawScene();</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">realDrawScene</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="comment">// Check if any events have been activiated (key pressed, mouse moved etc.) and call corresponding response functions</span></span><br><span class="line">        glfwPollEvents();</span><br><span class="line">        Do_Movement();</span><br><span class="line">        <span class="comment">// fbo</span></span><br><span class="line">        <span class="keyword">if</span> (fbo == <span class="literal">nullptr</span>)</span><br><span class="line">        &#123;</span><br><span class="line">            fbo = FboNode::create();</span><br><span class="line">        &#125;</span><br><span class="line">        fbo-&gt;beginDraw();</span><br><span class="line">        sortNodes();</span><br><span class="line">        drawNodes();</span><br><span class="line">        fbo-&gt;endDraw();</span><br><span class="line">        <span class="comment">// Render</span></span><br><span class="line">        <span class="comment">// Clear the colorbuffer</span></span><br><span class="line">        glClearColor(<span class="number">0.0f</span>, <span class="number">0.0f</span>, <span class="number">0.0f</span>, <span class="number">1.0f</span>);</span><br><span class="line">        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);</span><br><span class="line">        sortNodes();</span><br><span class="line">        drawNodes();</span><br><span class="line">        <span class="comment">// fbo</span></span><br><span class="line">        fbo-&gt;draw();</span><br><span class="line">        <span class="comment">// Swap the screen buffers</span></span><br><span class="line">        glfwSwapBuffers(window);</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">sortNodes</span><span class="params">()</span></span>;</span><br><span class="line">        sort(nodes.begin(), nodes.end(), [](OpenglNode* v1, OpenglNode* v2)-&gt;<span class="keyword">bool</span>&#123; <span class="keyword">return</span> v1-&gt;getZOrder() &lt; v2-&gt;getZOrder(); &#125;);</span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">drawNodes</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="keyword">for</span> (<span class="built_in">vector</span>&lt;OpenglNode*&gt;::iterator itr = nodes.begin(); itr != nodes.end(); itr++)</span><br><span class="line">            (*itr)-&gt;draw();</span><br></pre></td></tr></table></figure>

<p>ShaderProgram</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ShaderProgram</span></span></span><br><span class="line"><span class="class">    <span class="title">void</span> <span class="title">initWithSorce</span>(<span class="title">const</span> <span class="title">char</span>* <span class="title">vertexShaderSource</span>, <span class="title">const</span> <span class="title">char</span>* <span class="title">fragmentShaderSource</span>);</span></span><br><span class="line">        <span class="comment">// Vertex shader</span></span><br><span class="line">        <span class="keyword">const</span> GLchar *Vsources[] = &#123;</span><br><span class="line">            <span class="string">"#version 330 core\n"</span></span><br><span class="line">            <span class="string">"uniform mat4 model;\n"</span></span><br><span class="line">            <span class="string">"uniform mat4 view;    \n"</span></span><br><span class="line">            <span class="string">"uniform mat4 projection;\n"</span></span><br><span class="line">            <span class="string">"//custom INCLUDES END\n\n"</span>,</span><br><span class="line">            vertexShaderSource</span><br><span class="line">        &#125;;</span><br><span class="line">        GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER);</span><br><span class="line">        <span class="keyword">int</span> n = <span class="keyword">sizeof</span>(Vsources) / <span class="keyword">sizeof</span>(*Vsources);</span><br><span class="line">        glShaderSource(vertexShader, n, Vsources, <span class="literal">NULL</span>);</span><br><span class="line">        glCompileShader(vertexShader);</span><br><span class="line">        <span class="comment">// Fragment shader</span></span><br><span class="line">        <span class="keyword">const</span> GLchar *Fsources[] = &#123;</span><br><span class="line">            <span class="string">"#version 330 core\n"</span></span><br><span class="line">            <span class="string">"//custom INCLUDES END\n\n"</span>,</span><br><span class="line">            fragmentShaderSource</span><br><span class="line">        &#125;;</span><br><span class="line">        GLuint fragmentShader = glCreateShader(GL_FRAGMENT_SHADER);</span><br><span class="line">        glShaderSource(fragmentShader, <span class="keyword">sizeof</span>(Fsources) / <span class="keyword">sizeof</span>(*Fsources), Fsources, <span class="literal">NULL</span>);</span><br><span class="line">        glCompileShader(fragmentShader);</span><br><span class="line">        <span class="comment">// Link shaders</span></span><br><span class="line">        programID = glCreateProgram();</span><br><span class="line">        glAttachShader(programID, vertexShader);</span><br><span class="line">        glAttachShader(programID, fragmentShader);</span><br><span class="line">        glLinkProgram(programID);</span><br><span class="line">        <span class="comment">// program is ok, delete shader, and glDeleteShader(programID);</span></span><br><span class="line">        glDeleteShader(vertexShader);</span><br><span class="line">        glDeleteShader(fragmentShader);</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ShaderProgramCache</span></span></span><br><span class="line"><span class="class">    <span class="title">enum</span></span></span><br><span class="line"><span class="class">    &#123;</span></span><br><span class="line">        Position_Color_Shader,</span><br><span class="line">        Position_Color_Texture_Shader,</span><br><span class="line">        Position_Texture_Shader,</span><br><span class="line">        Model3d_Shader,</span><br><span class="line">        SkyBox_Shader,</span><br><span class="line">    &#125;;</span><br><span class="line">    <span class="built_in">std</span>::<span class="built_in">map</span>&lt;<span class="keyword">int</span>, ShaderProgram*&gt; shaders;</span><br><span class="line">    <span class="comment">// method --------------------------------</span></span><br><span class="line">    <span class="function">ShaderProgram* <span class="title">getShaderProgram</span><span class="params">(<span class="keyword">int</span> type)</span></span>;</span><br><span class="line">        <span class="keyword">auto</span> itr = shaders.find(type);</span><br><span class="line">        <span class="keyword">if</span> (itr != shaders.end())</span><br><span class="line">            <span class="keyword">return</span> itr-&gt;second;</span><br><span class="line">        ShaderProgram* shader = <span class="literal">nullptr</span>;</span><br><span class="line">        <span class="keyword">switch</span> (type)</span><br><span class="line">            <span class="keyword">case</span> Position_Color_Texture_Shader:</span><br><span class="line">                shader = <span class="keyword">new</span> ShaderProgram(srcPosition_Color_Texture_vert, srcPosition_Color_Texture_frag, <span class="number">0</span>);</span><br><span class="line">                <span class="keyword">break</span>;</span><br><span class="line">        shaders[type] = shader;</span><br><span class="line">        <span class="keyword">return</span> shader;</span><br><span class="line"></span><br><span class="line">Shader.h</span><br><span class="line">    <span class="keyword">extern</span> <span class="keyword">const</span> <span class="keyword">char</span> * srcPosition_Color_Texture_vert;</span><br><span class="line">    <span class="keyword">extern</span> <span class="keyword">const</span> <span class="keyword">char</span> * srcPosition_Color_Texture_frag;</span><br><span class="line">Shader.cpp</span><br><span class="line">    <span class="comment">// use include to get string</span></span><br><span class="line">    <span class="keyword">const</span> <span class="keyword">char</span> * srcPosition_Color_Texture_vert =</span><br><span class="line">#include <span class="string">"Position_Color_Texture.vs"</span></span><br><span class="line">    <span class="keyword">const</span> <span class="keyword">char</span> * srcPosition_Color_Texture_frag =</span><br><span class="line">#include <span class="string">"Position_Color_Texture.frag"</span></span><br><span class="line"></span><br><span class="line">Position_Color_Texture.vs</span><br><span class="line"><span class="string">"                                                    \n\</span></span><br><span class="line"><span class="string">layout (location = 0) in vec3 position;              \n\</span></span><br><span class="line"><span class="string">layout (location = 1) in vec3 color;                 \n\</span></span><br><span class="line"><span class="string">layout (location = 2) in vec2 texCoord;              \n\</span></span><br><span class="line"><span class="string">                                                     \n\</span></span><br><span class="line"><span class="string">out vec3 ourColor;                                   \n\</span></span><br><span class="line"><span class="string">out vec2 TexCoord;                                   \n\</span></span><br><span class="line"><span class="string">                                                     \n\</span></span><br><span class="line"><span class="string">void main()                                          \n\</span></span><br><span class="line"><span class="string">&#123;                                                    \n\</span></span><br><span class="line"><span class="string">    gl_Position = projection * view * model * vec4(position, 1.0f);                \n\</span></span><br><span class="line"><span class="string">    ourColor = color;                                \n\</span></span><br><span class="line"><span class="string">    TexCoord = vec2(texCoord.x, texCoord.y);         \n\</span></span><br><span class="line"><span class="string">&#125;                                                    \n\</span></span><br><span class="line"><span class="string">"</span>;</span><br><span class="line">Position_Color_Texture.frag</span><br><span class="line"><span class="string">"                                        \n\</span></span><br><span class="line"><span class="string">in vec3 ourColor;                        \n\</span></span><br><span class="line"><span class="string">in vec2 TexCoord;                        \n\</span></span><br><span class="line"><span class="string">                                         \n\</span></span><br><span class="line"><span class="string">uniform vec3 lightColor;                 \n\</span></span><br><span class="line"><span class="string">uniform sampler2D ourTexture;            \n\</span></span><br><span class="line"><span class="string">                                         \n\</span></span><br><span class="line"><span class="string">out vec4 color;                          \n\</span></span><br><span class="line"><span class="string">                                         \n\</span></span><br><span class="line"><span class="string">void main()                              \n\</span></span><br><span class="line"><span class="string">&#123;                                        \n\</span></span><br><span class="line"><span class="string">    vec4 texColor = texture(ourTexture, TexCoord);            \n\</span></span><br><span class="line"><span class="string">    color = texColor * vec4(ourColor * lightColor, 1.0f);     \n\</span></span><br><span class="line"><span class="string">&#125;                                        \n\</span></span><br><span class="line"><span class="string">"</span>;</span><br></pre></td></tr></table></figure>

<p>OpenglNode</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">OpenglNode</span></span></span><br><span class="line"><span class="class">    <span class="title">ShaderProgram</span>* <span class="title">shader</span>;</span></span><br><span class="line">    Texture* texture;</span><br><span class="line">    <span class="keyword">int</span> vertexCount;</span><br><span class="line">    <span class="keyword">float</span>* vertexPosition;</span><br><span class="line">    <span class="keyword">float</span>* vertexColor;</span><br><span class="line">    <span class="keyword">float</span>* vertexUV;</span><br><span class="line">    GLuint vao;</span><br><span class="line">    <span class="keyword">int</span> zOrder;</span><br><span class="line">    <span class="comment">// method -------------------------</span></span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">bool</span> <span class="title">init</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">draw</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="comment">// override me</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// Macro</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> NODE_DRAW_SETUP() \</span></span><br><span class="line">    <span class="keyword">do</span> &#123; \</span><br><span class="line">    glBindVertexArray(<span class="number">0</span>); \</span><br><span class="line">    glBindBuffer(GL_ARRAY_BUFFER, <span class="number">0</span>); \</span><br><span class="line">    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, <span class="number">0</span>); \</span><br><span class="line">    glBindTexture(GL_TEXTURE_2D, <span class="number">0</span>); \</span><br><span class="line">    getShaderProgram()-&gt;use(); \</span><br><span class="line">    &#125; <span class="keyword">while</span> (<span class="number">0</span>)</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> CREATE_FUNC(__TYPE__) \</span></span><br><span class="line">    static __TYPE__* create() \</span><br><span class="line">    &#123; \</span><br><span class="line">        __TYPE__ *pRet = <span class="keyword">new</span> __TYPE__(); \</span><br><span class="line">        <span class="keyword">if</span> (pRet &amp;&amp; pRet-&gt;init()) \</span><br><span class="line">        &#123; \</span><br><span class="line">            <span class="keyword">return</span> pRet; \</span><br><span class="line">        &#125; \</span><br><span class="line">        <span class="keyword">else</span> \</span><br><span class="line">        &#123; \</span><br><span class="line">            <span class="keyword">delete</span> pRet; \</span><br><span class="line">            pRet = <span class="literal">NULL</span>; \</span><br><span class="line">            <span class="keyword">return</span> <span class="literal">NULL</span>; \</span><br><span class="line">        &#125; \</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<p>三角形：TriangleNode</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">TriangleNode</span> :</span> <span class="keyword">public</span> OpenglNode</span><br><span class="line">    GLuint vbos[<span class="number">2</span>];</span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">bool</span> <span class="title">init</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="keyword">auto</span> shaderProgram = ShaderProgramCache::getInstance()-&gt;getShaderProgram(ShaderProgramCache::Position_Color_Shader);</span><br><span class="line">        setShaderProgram(shaderProgram);</span><br><span class="line">        vertexCount = <span class="number">3</span>;</span><br><span class="line">        vertexPosition = <span class="keyword">new</span> <span class="keyword">float</span>[vertexCount * <span class="number">3</span>];<span class="comment">// xyz: (-1.0f,-1.0f,0.0f), (0,1,0), (1,-1,0)</span></span><br><span class="line">        vertexColor = <span class="keyword">new</span> <span class="keyword">float</span>[vertexCount * <span class="number">3</span>];<span class="comment">// rgb: (0.9, 0.1, 0.1), ...</span></span><br><span class="line">        glGenVertexArrays(<span class="number">1</span>, &amp;vao);</span><br><span class="line">        glGenBuffers(<span class="number">2</span>, vbos);</span><br><span class="line">        glBindVertexArray(vao);</span><br><span class="line">        <span class="comment">// vertexPosition</span></span><br><span class="line">        glBindBuffer(GL_ARRAY_BUFFER, vbos[<span class="number">0</span>]);</span><br><span class="line">        glBufferData(GL_ARRAY_BUFFER, <span class="keyword">sizeof</span>(<span class="keyword">float</span>)* vertexCount * <span class="number">3</span>, vertexPosition, GL_STATIC_DRAW);</span><br><span class="line">        glEnableVertexAttribArray(<span class="number">0</span>);</span><br><span class="line">        glVertexAttribPointer(<span class="number">0</span>, <span class="number">3</span>, GL_FLOAT, GL_FALSE, <span class="number">3</span> * <span class="keyword">sizeof</span>(GLfloat), (GLvoid*)<span class="number">0</span>);</span><br><span class="line">        <span class="comment">// vertexColor</span></span><br><span class="line">        glBindBuffer(GL_ARRAY_BUFFER, vbos[<span class="number">1</span>]);</span><br><span class="line">        glBufferData(GL_ARRAY_BUFFER, <span class="keyword">sizeof</span>(<span class="keyword">float</span>)* vertexCount * <span class="number">3</span>, vertexColor, GL_STATIC_DRAW);</span><br><span class="line">        glEnableVertexAttribArray(<span class="number">1</span>);</span><br><span class="line">        glVertexAttribPointer(<span class="number">1</span>, <span class="number">3</span>, GL_FLOAT, GL_FALSE, <span class="number">3</span> * <span class="keyword">sizeof</span>(GLfloat), (GLvoid*)<span class="number">0</span>);</span><br><span class="line">        <span class="comment">// over vao</span></span><br><span class="line">        glBindVertexArray(<span class="number">0</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">draw</span><span class="params">()</span></span>;</span><br><span class="line">        NODE_DRAW_SETUP();</span><br><span class="line">        glm::mat4 model;</span><br><span class="line">        getShaderProgram()-&gt;updateMVP(model);</span><br><span class="line">        glBindVertexArray(vao);</span><br><span class="line">        glDrawArrays(GL_TRIANGLES, <span class="number">0</span>, vertexCount);</span><br><span class="line">        glBindVertexArray(<span class="number">0</span>);</span><br></pre></td></tr></table></figure>

<p>ShaderProgram::updateMVP</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> ShaderProgram::updateMVP(glm::mat4 &amp;model, <span class="keyword">bool</span> forceSetSkyBox)</span><br><span class="line">    <span class="comment">// Create camera transformation</span></span><br><span class="line">    glm::mat4 view;</span><br><span class="line">    glm::mat4 projection;</span><br><span class="line">    <span class="keyword">auto</span> camera = Director::getInstance()-&gt;getCamera();</span><br><span class="line">    <span class="keyword">if</span> (camera)</span><br><span class="line">    &#123;</span><br><span class="line">        view = camera-&gt;GetViewMatrix();</span><br><span class="line">        <span class="keyword">float</span> v = camera-&gt;Zoom;</span><br><span class="line">        <span class="keyword">float</span> s = (<span class="keyword">float</span>)Director::getInstance()-&gt;getViewPortSizeWidth() / (<span class="keyword">float</span>)Director::getInstance()-&gt;getViewPortSizeHeight();</span><br><span class="line">        projection = glm::perspective(glm::radians(v), s, <span class="number">0.1f</span>, <span class="number">1000.0f</span>);</span><br><span class="line">    &#125;</span><br><span class="line">    GLint lightLoc = glGetUniformLocation(programID, <span class="string">"lightColor"</span>);</span><br><span class="line">    glUniform3f(lightLoc, lightColor.x, lightColor.y, lightColor.z);</span><br><span class="line">    <span class="comment">// Get the uniform locations</span></span><br><span class="line">    GLint modelLoc = glGetUniformLocation(programID, <span class="string">"model"</span>);</span><br><span class="line">    GLint viewLoc = glGetUniformLocation(programID, <span class="string">"view"</span>);</span><br><span class="line">    GLint projLoc = glGetUniformLocation(programID, <span class="string">"projection"</span>);</span><br><span class="line">    <span class="comment">// Pass the matrices to the shader</span></span><br><span class="line">    glUniformMatrix4fv(modelLoc, <span class="number">1</span>, GL_FALSE, glm::value_ptr(model));</span><br><span class="line">    glUniformMatrix4fv(viewLoc, <span class="number">1</span>, GL_FALSE, glm::value_ptr(view));</span><br><span class="line">    glUniformMatrix4fv(projLoc, <span class="number">1</span>, GL_FALSE, glm::value_ptr(projection));</span><br></pre></td></tr></table></figure>

<p>图片：ImageNode</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">ImageNode</span> :</span> <span class="keyword">public</span> OpenglNode</span><br><span class="line">    GLuint vbos[<span class="number">4</span>];</span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">bool</span> <span class="title">init</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="keyword">auto</span> shaderProgram = ShaderProgramCache::getInstance()-&gt;getShaderProgram(ShaderProgramCache::Position_Color_Texture_Shader);</span><br><span class="line">        setShaderProgram(shaderProgram);</span><br><span class="line">        <span class="comment">/*</span></span><br><span class="line"><span class="comment">        * 3 2</span></span><br><span class="line"><span class="comment">        * 0 1</span></span><br><span class="line"><span class="comment">        */</span></span><br><span class="line">        vertexCount = <span class="number">4</span>;</span><br><span class="line">        vertexPosition = <span class="keyword">new</span> <span class="keyword">float</span>[vertexCount * <span class="number">3</span>];<span class="comment">// 4角顶点</span></span><br><span class="line">        vertexColor = <span class="keyword">new</span> <span class="keyword">float</span>[vertexCount * <span class="number">3</span>];<span class="comment">// 4角顶点rgb，全1</span></span><br><span class="line">        vertexUV = <span class="keyword">new</span> <span class="keyword">float</span>[vertexCount * <span class="number">2</span>];<span class="comment">// 4角uv,注意纹理数据一般从左上作为原点</span></span><br><span class="line">        GLuint indices[] = &#123;</span><br><span class="line">            <span class="number">0</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="comment">// First Triangle</span></span><br><span class="line">            <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>  <span class="comment">// Second Triangle</span></span><br><span class="line">        &#125;;</span><br><span class="line">        setTexture(TextureCache::getInstance()-&gt;getTextureFromFile(<span class="string">"img/grass.png"</span>));</span><br><span class="line">        glGenVertexArrays(<span class="number">1</span>, &amp;vao);</span><br><span class="line">        glGenBuffers(<span class="number">4</span>, vbos);</span><br><span class="line">        glBindVertexArray(vao);</span><br><span class="line">        <span class="comment">// vertexPosition</span></span><br><span class="line">        glBindBuffer(GL_ARRAY_BUFFER, vbos[<span class="number">0</span>]);</span><br><span class="line">        glBufferData(GL_ARRAY_BUFFER, <span class="keyword">sizeof</span>(<span class="keyword">float</span>)* vertexCount * <span class="number">3</span>, vertexPosition, GL_STATIC_DRAW);</span><br><span class="line">        glEnableVertexAttribArray(<span class="number">0</span>);</span><br><span class="line">        glVertexAttribPointer(<span class="number">0</span>, <span class="number">3</span>, GL_FLOAT, GL_FALSE, <span class="number">3</span> * <span class="keyword">sizeof</span>(GLfloat), (GLvoid*)<span class="number">0</span>);</span><br><span class="line">        <span class="comment">// vertexColor</span></span><br><span class="line">        glBindBuffer(GL_ARRAY_BUFFER, vbos[<span class="number">1</span>]);</span><br><span class="line">        glBufferData(GL_ARRAY_BUFFER, <span class="keyword">sizeof</span>(<span class="keyword">float</span>)* vertexCount * <span class="number">3</span>, vertexColor, GL_STATIC_DRAW);</span><br><span class="line">        glEnableVertexAttribArray(<span class="number">1</span>);</span><br><span class="line">        glVertexAttribPointer(<span class="number">1</span>, <span class="number">3</span>, GL_FLOAT, GL_FALSE, <span class="number">3</span> * <span class="keyword">sizeof</span>(GLfloat), (GLvoid*)<span class="number">0</span>);</span><br><span class="line">        <span class="comment">// vertexUV</span></span><br><span class="line">        glBindBuffer(GL_ARRAY_BUFFER, vbos[<span class="number">2</span>]);</span><br><span class="line">        glBufferData(GL_ARRAY_BUFFER, <span class="keyword">sizeof</span>(<span class="keyword">float</span>)* vertexCount * <span class="number">2</span>, vertexUV, GL_STATIC_DRAW);</span><br><span class="line">        glEnableVertexAttribArray(<span class="number">2</span>);</span><br><span class="line">        glVertexAttribPointer(<span class="number">2</span>, <span class="number">2</span>, GL_FLOAT, GL_FALSE, <span class="number">2</span> * <span class="keyword">sizeof</span>(GLfloat), (GLvoid*)<span class="number">0</span>);</span><br><span class="line">        <span class="comment">// indices</span></span><br><span class="line">        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbos[<span class="number">3</span>]);</span><br><span class="line">        glBufferData(GL_ELEMENT_ARRAY_BUFFER, <span class="keyword">sizeof</span>(indices), indices, GL_STATIC_DRAW);</span><br><span class="line">        <span class="comment">// over vao</span></span><br><span class="line">        glBindVertexArray(<span class="number">0</span>);</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">    <span class="function"><span class="keyword">virtual</span> <span class="keyword">void</span> <span class="title">draw</span><span class="params">()</span></span>;</span><br><span class="line">        glEnable(GL_BLEND);</span><br><span class="line">        <span class="comment">// 在RGBA模式下,此混合是源颜色（即将渲染的颜色）的透明度作为主导，即渲染透明度</span></span><br><span class="line">        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);</span><br><span class="line">        NODE_DRAW_SETUP();</span><br><span class="line">        glActiveTexture(GL_TEXTURE0);</span><br><span class="line">        getTexture()-&gt;bindTexture();</span><br><span class="line">        getShaderProgram()-&gt;setUniformTexture(<span class="string">"ourTexture"</span>, <span class="number">0</span>);</span><br><span class="line">        glm::mat4 trans;</span><br><span class="line">        trans = glm::translate(trans, glm::vec3(<span class="number">0.0</span>, <span class="number">0.0</span>, <span class="number">1.0</span>));</span><br><span class="line">        trans = glm::scale(trans, glm::vec3(<span class="number">0.9</span>, <span class="number">0.9</span>, <span class="number">0.9</span>));</span><br><span class="line">        getShaderProgram()-&gt;updateMVP(trans);</span><br><span class="line">        glBindVertexArray(vao);</span><br><span class="line">        glDrawElements(GL_TRIANGLES, <span class="number">6</span>, GL_UNSIGNED_INT, <span class="number">0</span>);</span><br><span class="line">        glBindVertexArray(<span class="number">0</span>);</span><br><span class="line">        glDisable(GL_BLEND);</span><br></pre></td></tr></table></figure>

<p>CameraView</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">CameraView</span></span></span><br><span class="line"><span class="class">    <span class="title">glm</span>:</span>:vec3 Position;</span><br><span class="line">    glm::vec3 Front;</span><br><span class="line">    glm::vec3 Up;</span><br><span class="line">    glm::vec3 Right;</span><br><span class="line">    glm::vec3 WorldUp;</span><br><span class="line">    GLfloat Yaw;        <span class="comment">//偏航角</span></span><br><span class="line">    GLfloat Pitch;      <span class="comment">//俯仰角</span></span><br><span class="line">    <span class="function"><span class="keyword">void</span> <span class="title">updateCameraVectors</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="comment">// Calculate the new Front vector</span></span><br><span class="line">        glm::vec3 front;</span><br><span class="line">        <span class="comment">// 摄像机可以移动、旋转(鼠标有横向和纵向，所以是绕y(Yaw、摇头),x旋转(Pitch、点头)，如果是绕z(Roll)旋转，则为“小钻风”动作)</span></span><br><span class="line">        front.x = <span class="built_in">cos</span>(glm::radians(<span class="keyword">this</span>-&gt;Yaw)) * <span class="built_in">cos</span>(glm::radians(<span class="keyword">this</span>-&gt;Pitch));</span><br><span class="line">        front.y = <span class="built_in">sin</span>(glm::radians(<span class="keyword">this</span>-&gt;Pitch));</span><br><span class="line">        front.z = <span class="built_in">sin</span>(glm::radians(<span class="keyword">this</span>-&gt;Yaw)) * <span class="built_in">cos</span>(glm::radians(<span class="keyword">this</span>-&gt;Pitch));</span><br><span class="line">        <span class="keyword">this</span>-&gt;Front = glm::normalize(front);</span><br><span class="line">        <span class="comment">// Also re-calculate the Right and Up vector，两向量叉乘得到垂直于他们的向量，乘法两侧的顺序决定积的方向(右手定则)</span></span><br><span class="line">        <span class="keyword">this</span>-&gt;Right = glm::normalize(glm::cross(<span class="keyword">this</span>-&gt;Front, <span class="keyword">this</span>-&gt;WorldUp));</span><br><span class="line">        <span class="comment">// 最终需要这个Up</span></span><br><span class="line">        <span class="keyword">this</span>-&gt;Up = glm::normalize(glm::cross(<span class="keyword">this</span>-&gt;Right, <span class="keyword">this</span>-&gt;Front));</span><br><span class="line">    glm::<span class="function">mat4 <span class="title">GetViewMatrix</span><span class="params">()</span></span>;</span><br><span class="line">        <span class="comment">// 观察矩阵（摄像机矩阵）: glm::LookAt函数需要一个位置、目标和上向量</span></span><br><span class="line">        <span class="comment">// this-&gt;Position + this-&gt;Front结果为摄像机所看的位置在世界坐标系中的坐标</span></span><br><span class="line">        <span class="keyword">return</span> glm::lookAt(<span class="keyword">this</span>-&gt;Position, <span class="keyword">this</span>-&gt;Position + <span class="keyword">this</span>-&gt;Front, <span class="keyword">this</span>-&gt;Up);</span><br><span class="line"></span><br><span class="line"><span class="comment">// 一种简单的，固定位置，固定观察世界原点的摄像机矩阵</span></span><br><span class="line">glm::vec3 cameraPos = glm::vec3(<span class="number">0.0f</span>, <span class="number">0.0f</span>, <span class="number">3.0f</span>);</span><br><span class="line">glm::vec3 cameraTarget = glm::vec3(<span class="number">0.0f</span>, <span class="number">0.0f</span>, <span class="number">0.0f</span>);</span><br><span class="line"><span class="comment">// 方向向量(Direction Vector)并不是最好的名字，因为它实际上指向从它到目标向量的相反方向</span></span><br><span class="line">glm::vec3 cameraDirection = glm::normalize(cameraPos - cameraTarget);</span><br><span class="line"><span class="comment">// 摄像机的观察方向（朝向），就是CameraView的Front，是指摄像机指向世界原点的向量：cameraTarget - cameraPos</span></span><br><span class="line"><span class="comment">// 摄像机的坐标系z轴，和观察方向相反</span></span><br><span class="line"><span class="comment">// 可以理解为摄像机也是一个世界坐标系中的物体，它的目的是把世界坐标系中的物体转化到摄像机坐标系中</span></span><br><span class="line">glm::vec3 up = glm::vec3(<span class="number">0.0f</span>, <span class="number">1.0f</span>, <span class="number">0.0f</span>); </span><br><span class="line"><span class="comment">// 右手从up伸，手指向cameraDirection完全，大拇指的方向为cameraRight的方向</span></span><br><span class="line">glm::vec3 cameraRight = glm::normalize(glm::cross(up, cameraDirection));</span><br><span class="line">glm::vec3 cameraUp = glm::cross(cameraDirection, cameraRight);</span><br><span class="line"><span class="comment">// 自己进行坐标系转化要麻烦，这里使用lookAt：摄像机在世界坐标系的位置，要观察的世界坐标系位置，摄像机本身坐标系中的上方向</span></span><br><span class="line">glm::mat4 view = glm::lookAt(cameraPos, cameraTarget, cameraUp);</span><br></pre></td></tr></table></figure>

<p>MVP</p>
<figure class="highlight c++"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">局部空间,世界空间,观察空间,裁剪空间</span><br><span class="line">glm::mat4 model;</span><br><span class="line">model = glm::rotate(model, glm::radians(<span class="number">-55.0f</span>), glm::vec3(<span class="number">1.0f</span>, <span class="number">0.0f</span>, <span class="number">0.0f</span>));</span><br><span class="line">glm::mat4 view;</span><br><span class="line"><span class="comment">// 摄像机向z轴正方向，移动等价于世界向z轴负方向移动</span></span><br><span class="line">view = glm::translate(view, glm::vec3(<span class="number">0.0f</span>, <span class="number">0.0f</span>, <span class="number">-3.0f</span>));</span><br><span class="line">glm::mat4 projection;</span><br><span class="line">projection = glm::perspective(glm::radians(<span class="number">45.0f</span>), screenWidth / screenHeight, <span class="number">0.1f</span>, <span class="number">100.0f</span>);</span><br><span class="line">gl_Position = projection * view * model * vec4(aPos, <span class="number">1.0</span>);</span><br></pre></td></tr></table></figure>


      
    </div>
    
  </div>
  
    


    <nav id="article-nav">
        
            <div id="article-nav-newer" class="article-nav-title">
                <a href="/mytpages/2019/11/23/编译cpp-准备/">
                    编译c++准备
                </a>
            </div>
        
        
            <div id="article-nav-older" class="article-nav-title">
                <a href="/mytpages/2019/11/15/cocos2dx-action/">
                    cocos2dx-action
                </a>
            </div>
        
    </nav>

  
</article>

    <div id="toc" class="toc-article">
        <strong class="toc-title">文章目录</strong>
        
            
        
    </div>
    <style>
        .left-col .switch-btn,
        .left-col .switch-area {
            display: none;
        }
        .toc-level-3 i,
        .toc-level-3 ol {
            display: none !important;
        }
    </style>

    <input type="button" id="tocButton" value="隐藏目录"  title="点击按钮隐藏或者显示文章目录">

    <script>
        yiliaConfig.toc = ["隐藏目录", "显示目录", !!"false"];
    </script>



    
<div class="share">
    
        <div class="bdsharebuttonbox">
            <a href="#" class="fa fa-twitter bds_twi" data-cmd="twi" title="分享到推特"></a>
            <a href="#" class="fa fa-weibo bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a>
            <a href="#" class="fa fa-qq bds_sqq" data-cmd="sqq" title="分享给 QQ 好友"></a>
            <a href="#" class="fa fa-files-o bds_copy" data-cmd="copy" title="复制网址"></a>
            <a href="#" class="fa fa fa-envelope-o bds_mail" data-cmd="mail" title="通过邮件分享"></a>
            <a href="#" class="fa fa-weixin bds_weixin" data-cmd="weixin" title="生成文章二维码"></a>
            <a href="#" class="fa fa-share-alt bds_more" data-cmd="more"></i></a>
        </div>
        <script>
            window._bd_share_config={
                "common":{"bdSnsKey":{},"bdText":"simple opengl　| Xbiubiubiu　","bdMini":"2","bdMiniList":false,"bdPic":"","bdStyle":"0","bdSize":"24"},"share":{}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];
        </script>
    

    
</div>







    




    <div class="scroll" id="post-nav-button">
        
            <a href="/mytpages/2019/11/23/编译cpp-准备/" title="上一篇: 编译c++准备">
                <i class="fa fa-angle-left"></i>
            </a>
        

        <a title="文章列表"><i class="fa fa-bars"></i><i class="fa fa-times"></i></a>

        
            <a href="/mytpages/2019/11/15/cocos2dx-action/" title="下一篇: cocos2dx-action">
                <i class="fa fa-angle-right"></i>
            </a>
        
    </div>

    <ul class="post-list"><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/12/13/cpp：allocator-new/">cpp：allocator,new</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/28/CPP标准库-note/">CPP标准库-note</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/27/C与win32API/">C与win32API</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/27/C标准库-note/">C标准库</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/26/cpp的lib和dll/">cpp的lib和dll</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/25/编译cpp-vs2015/">编译cpp-vs2015</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/23/编译cpp-准备/">编译c++准备</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/18/simple-opengl/">simple opengl</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/15/cocos2dx-action/">cocos2dx-action</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/15/cocos2dx-schedule/">cocos2dx-schedule</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx在win32上写日志文件/">cocos2dx在win32上写日志文件</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx在win32上播放ogg/">cocos2dx在win32上播放ogg</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx字库缺失文字处理/">cocos2dx字库缺失文字处理</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/14/cocos2dx工作目录修改/">cocos2dx工作目录修改</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/13/cocos2dx-android/">cocos2dx-android</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/12/cocos2dx-win32/">cocos2dx-win32</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/11/Sublimer-Text/">Sublimer Text</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/07/潜意识？？设计模式/">潜意识？？设计模式</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/04/BST？AVL？红黑树？/">BST？AVL？红黑树？</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/11/01/几种排序算法示例代码/">几种排序算法示例代码</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/31/引子-基础算法？？/">引子-基础算法？？</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/31/引子-数据结构？？/">引子-数据结构？？</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/25/不会懂分布式系统的/">不会懂分布式系统的</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/24/MySql简单使用-adv/">MySql简单使用-adv</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/24/MySql简单使用/">MySql简单使用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/18/PS3-HEN破相关记录/">PS3-HEN破相关记录</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/09/测试使用云函数扩展码云page/">测试使用云函数扩展码云page</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/10/09/web3-单页Web应用/">web3.单页Web应用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/29/web2-简单网站的前后端分离/">web2.简单网站的前后端分离</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/29/web1-创建一个简单的网站/">web1.创建一个简单的网站</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/NodeJS-简单使用/">NodeJS 简单使用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/JavaScript-other/">JavaScript-other</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/JavaScript-模块/">JavaScript-模块</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/JavaScript-简单使用/">JavaScript 简单使用</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/27/github-gitee-chrome文件树插件/">github & gitee chrome文件树插件</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/26/markdown-简单使用/">markdown 简单使用示例</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/25/hello-world/">Hello World</a></li><li class="post-list-item"><a class="post-list-link" href="/mytpages/2019/09/24/zzTest-article0/">zzTest article0</a></li></ul>




    <script>
        
    </script>
</div>
      <footer id="footer">
    <div class="outer">
        <div id="footer-info">
            <div class="footer-left">
                <i class="fa fa-copyright"></i> 
                2019-2020 Ren ZM
            </div>
            <div class="footer-right">
                <a href="http://hexo.io/" target="_blank" title="快速、简洁且高效的博客框架">Hexo</a>  Theme <a href="https://github.com/MOxFIVE/hexo-theme-yelee" target="_blank" title="简而不减 Hexo 双栏博客主题  v3.5">Yelee</a> by MOxFIVE <i class="fa fa-heart animated infinite pulse"></i>
            </div>
        </div>
        
            <div class="visit">
                
                    <span id="busuanzi_container_site_pv" style='display:none'>
                        <span id="site-visit" title="本站到访数"><i class="fa fa-user" aria-hidden="true"></i><span id="busuanzi_value_site_uv"></span>
                        </span>
                    </span>
                
                
                    <span>| </span>
                
                
                    <span id="busuanzi_container_page_pv" style='display:none'>
                        <span id="page-visit"  title="本页阅读量"><i class="fa fa-eye animated infinite pulse" aria-hidden="true"></i><span id="busuanzi_value_page_pv"></span>
                        </span>
                    </span>
                
            </div>
        
    </div>
</footer>
    </div>
    
<script data-main="/mytpages/js/main.js" src="//cdn.bootcss.com/require.js/2.2.0/require.min.js"></script>

    <script>
        $(document).ready(function() {
            var iPad = window.navigator.userAgent.indexOf('iPad');
            if (iPad > -1 || $(".left-col").css("display") === "none") {
                var bgColorList = ["#9db3f4", "#414141", "#e5a859", "#f5dfc6", "#c084a0", "#847e72", "#cd8390", "#996731"];
                var bgColor = Math.ceil(Math.random() * (bgColorList.length - 1));
                $("body").css({"background-color": bgColorList[bgColor], "background-size": "cover"});
            }
            else {
                var backgroundnum = 5;
                var backgroundimg = "url(/mytpages//background/bg-x.jpg)".replace(/x/gi, Math.ceil(Math.random() * backgroundnum));
                $("body").css({"background": backgroundimg, "background-attachment": "fixed", "background-size": "cover"});
            }
        })
    </script>





<div class="scroll" id="scroll">
    <a href="#" title="返回顶部"><i class="fa fa-arrow-up"></i></a>
    <a href="#comments" onclick="load$hide();" title="查看评论"><i class="fa fa-comments-o"></i></a>
    <a href="#footer" title="转到底部"><i class="fa fa-arrow-down"></i></a>
</div>
<script>
    // Open in New Window
    
        var oOpenInNew = {
            
            
            
            
            
            
             archives: ".archive-article-title", 
             miniArchives: "a.post-list-link", 
            
             friends: "#js-friends a", 
             socail: ".social a" 
        }
        for (var x in oOpenInNew) {
            $(oOpenInNew[x]).attr("target", "_blank");
        }
    
</script>

<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js">
</script>
  </div>
</body>
</html>